﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcBHXH.Common;

namespace MvcBHXH.Models
{
    class HuyenModel
    {
        private DataClassesBHYTTNDataContext context;
        public HuyenModel() 
        {
            context = Util.CreateInstance().DataContext();
        }

        public List<HuyenModel> GetHuyenModel()
        {
            var Huyen = from fc in context.tbl_Huyens
                        select new 
                        {
                            fc.Ma_Tinh,
                            fc.Ma_Huyen,
                            fc.Ten_Huyen,
                            fc.GhiChu,
                        };
            List<HuyenModel> listHuyenModel = new List<HuyenModel>();
            HuyenModel huyenModel;
            foreach (var item in Huyen)
            {
                huyenModel = new HuyenModel();
                huyenModel.Tinh = item.Ma_Tinh;
                huyenModel.MaHuyen = item.Ma_Huyen;
                huyenModel.TenHuyen = item.Ten_Huyen;
                huyenModel.GhiChu = item.GhiChu;
                listHuyenModel.Add(huyenModel);
            }
            return listHuyenModel;
        }


        public List<HuyenModel> GetHuyenByTinh(string maTinh)
        {
            var Huyen = from fc in context.tbl_Huyens where fc.Ma_Tinh.Equals(maTinh)
                        select new
                        {
                            fc.Ma_Tinh,
                            fc.Ma_Huyen,
                            fc.Ten_Huyen,
                            fc.GhiChu,
                        };
            List<HuyenModel> listHuyenModel = new List<HuyenModel>();
            HuyenModel huyenModel;
            foreach (var item in Huyen)
            {
                huyenModel = new HuyenModel();
                huyenModel.Tinh = item.Ma_Tinh;
                huyenModel.MaHuyen = item.Ma_Huyen;
                huyenModel.TenHuyen = item.Ten_Huyen;
                huyenModel.GhiChu = item.GhiChu;
                listHuyenModel.Add(huyenModel);
            }
            return listHuyenModel;
        }

        private string tinh;

        public string Tinh
        {
            get { return tinh; }
            set { tinh = value; }
        }
        private string maHuyen;

        public string MaHuyen
        {
            get { return maHuyen; }
            set { maHuyen = value; }
        }
        private string tenHuyen;

        public string TenHuyen
        {
            get { return tenHuyen; }
            set { tenHuyen = value; }
        }
        private string ghiChu;

        public string GhiChu
        {
            get { return ghiChu; }
            set { ghiChu = value; }
        }

    }
}
